<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  
  <title>山海经 题解 | Hexo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="毒瘤题目，体验极差">
<meta property="og:type" content="article">
<meta property="og:title" content="山海经 题解">
<meta property="og:url" content="http://example.com/2021/07/29/%E5%B1%B1%E6%B5%B7%E7%BB%8F%20%E9%A2%98%E8%A7%A3/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="毒瘤题目，体验极差">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2021-07-29T13:19:51.717Z">
<meta property="article:modified_time" content="2023-07-19T11:50:35.698Z">
<meta property="article:author" content="John Doe">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/atom.xml" title="Hexo" type="application/atom+xml">
  
  
    <link rel="shortcut icon" href="/favicon.png">
  
  
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/typeface-source-code-pro@0.0.71/index.min.css">

  
  
<link rel="stylesheet" href="/css/style.css">

  
    
<link rel="stylesheet" href="/fancybox/jquery.fancybox.min.css">

  
  
<meta name="generator" content="Hexo 6.3.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Hexo</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"><span class="fa fa-bars"></span></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
        
          <a class="nav-icon" href="/atom.xml" title="RSS Feed"><span class="fa fa-rss"></span></a>
        
        <a class="nav-icon nav-search-btn" title="Search"><span class="fa fa-search"></span></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://example.com"></form>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main"><article id="post-山海经 题解" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/2021/07/29/%E5%B1%B1%E6%B5%B7%E7%BB%8F%20%E9%A2%98%E8%A7%A3/" class="article-date">
  <time class="dt-published" datetime="2021-07-29T13:19:51.717Z" itemprop="datePublished">2021-07-29</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="p-name article-title" itemprop="headline name">
      山海经 题解
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <p>毒瘤题目，体验极差</p>
<h1 id="0-题目大意"><a href="#0-题目大意" class="headerlink" title="0.题目大意"></a>0.题目大意</h1><p>给出一个序列，每次查询一个区间的最大子段和的端点和值。序列长度 $n \le 10^{5}$ 。</p>
<h1 id="1-思路"><a href="#1-思路" class="headerlink" title="1.思路"></a>1.思路</h1><p><del>显然</del>应该使用线段树。题目要求每次求一个区间的最大子段和，那么在线段树节点中应该维护这个节点的最大子段和。然而，只维护最大子段和是无法从子节点合并出父节点的。</p>
<p>考虑一个节点，它的最大子段和可能有以下几个来源：</p>
<p>1.<br><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">|_____________________________|               &lt;-节点</span><br><span class="line">   |_________|                                               &lt;-最大子段和</span><br><span class="line">|_______________ |_____________|               &lt;-左右子节点</span><br></pre></td></tr></table></figure><br>2.<br><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">|_____________________________|               &lt;-节点</span><br><span class="line">                   |_________|                  &lt;-最大子段和</span><br><span class="line">|_______________ |_____________|               &lt;-左右子节点</span><br></pre></td></tr></table></figure><br>3.<br><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">|_____________________________|               &lt;-节点</span><br><span class="line">        |_________________|                            &lt;-最大子段和</span><br><span class="line">|_______________ |_____________|               &lt;-左右子节点</span><br></pre></td></tr></table></figure></p>
<p>情况1、2比较容易处理（直接照搬子节点的最大子段和），下面主要考虑情况3（最大子段和跨过中点）。</p>
<p>注意到可以把情况3拆分成这样：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">|_____________________________|               &lt;-节点</span><br><span class="line">    |__________| |_____|                            &lt;-最大子段和</span><br><span class="line">|______________| |_____________|               &lt;-左右子节点</span><br></pre></td></tr></table></figure>
<p>即拆分成左子节点的后缀和右子节点的前缀，所以考虑维护每个节点的 <strong>最大前缀和</strong> 与 <strong>最大后缀和</strong> ，情况3就可以表示为左子节点的最大后缀和和右子节点的最大前缀和的并，然后就可以愉快地合并了。</p>
<p>解决了如何合并的问题，剩下的几乎就是模板了</p>
<h1 id="2-坑点与吐槽"><a href="#2-坑点与吐槽" class="headerlink" title="2.坑点与吐槽"></a>2.坑点与吐槽</h1><ol>
<li>题目要求按照字典序输出，这莫名其妙地增加了许多难度</li>
<li>需要输出端点，这莫名其妙地增加了许多要维护的变量，又莫名其妙地增加了许多难度</li>
<li>综上所述，出题人是一个大毒瘤，<del>建议枪毙</del></li>
</ol>
<h1 id="3-Code"><a href="#3-Code" class="headerlink" title="3.Code"></a>3.Code</h1><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;bits/stdc++.h&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"><span class="meta">#<span class="keyword">define</span> MAXN 100000</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> INF 0x3fffffff</span></span><br><span class="line"><span class="keyword">struct</span> <span class="title class_">answ</span>&#123;</span><br><span class="line">    <span class="type">int</span> i,j,k;</span><br><span class="line">    <span class="built_in">answ</span>()&#123;i=j=k=<span class="number">0</span>;&#125;</span><br><span class="line">    <span class="built_in">answ</span>(<span class="type">int</span> _i,<span class="type">int</span> _j,<span class="type">int</span> _k)&#123;i=_i;j=_j;k=_k;&#125;</span><br><span class="line">&#125;;</span><br><span class="line"><span class="keyword">struct</span> <span class="title class_">segment_tree</span>&#123;</span><br><span class="line">    <span class="type">int</span> lp,rp;</span><br><span class="line">    segment_tree *ls,*rs;</span><br><span class="line">    <span class="type">int</span> sum,max_qz_sum,max_qz_sum_rp,max_hz_sum,max_hz_sum_lp,max_sum,max_sum_lp,max_sum_rp;</span><br><span class="line">    <span class="built_in">segment_tree</span>(<span class="type">int</span> a[],<span class="type">int</span> l,<span class="type">int</span> r)&#123;</span><br><span class="line">        lp=l;</span><br><span class="line">        rp=r;</span><br><span class="line">        <span class="keyword">if</span>(l==r)&#123;</span><br><span class="line">            ls=rs=<span class="literal">NULL</span>;</span><br><span class="line">            sum=max_qz_sum=max_hz_sum=max_sum=a[l];</span><br><span class="line">            max_qz_sum_rp=max_hz_sum_lp=max_sum_lp=max_sum_rp=l;</span><br><span class="line">        &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">            <span class="type">int</span> mid=(l+r)/<span class="number">2</span>;</span><br><span class="line">            ls=<span class="keyword">new</span> <span class="built_in">segment_tree</span>(a,l,mid);</span><br><span class="line">            rs=<span class="keyword">new</span> <span class="built_in">segment_tree</span>(a,mid+<span class="number">1</span>,r);</span><br><span class="line">            sum=ls-&gt;sum+rs-&gt;sum;</span><br><span class="line">            <span class="keyword">if</span>(ls-&gt;max_qz_sum &gt;= ls-&gt;sum+rs-&gt;max_qz_sum)&#123;<span class="comment">//情况1</span></span><br><span class="line">                max_qz_sum=ls-&gt;max_qz_sum;</span><br><span class="line">                max_qz_sum_rp=ls-&gt;max_qz_sum_rp;</span><br><span class="line">            &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">                max_qz_sum=ls-&gt;sum+rs-&gt;max_qz_sum;</span><br><span class="line">                max_qz_sum_rp=rs-&gt;max_qz_sum_rp;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">if</span>(rs-&gt;max_hz_sum &gt;= rs-&gt;sum+ls-&gt;max_hz_sum)&#123;<span class="comment">//情况2</span></span><br><span class="line">                max_hz_sum=rs-&gt;max_hz_sum;</span><br><span class="line">                max_hz_sum_lp=rs-&gt;max_hz_sum_lp;</span><br><span class="line">            &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">                max_hz_sum=rs-&gt;sum+ls-&gt;max_hz_sum;</span><br><span class="line">                max_hz_sum_lp=ls-&gt;max_hz_sum_lp;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">if</span>(ls-&gt;max_sum &gt;= rs-&gt;max_sum)&#123;<span class="comment">//情况3</span></span><br><span class="line">                max_sum=ls-&gt;max_sum;</span><br><span class="line">                max_sum_lp=ls-&gt;max_sum_lp;</span><br><span class="line">                max_sum_rp=ls-&gt;max_sum_rp;</span><br><span class="line">            &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">                max_sum=rs-&gt;max_sum;</span><br><span class="line">                max_sum_lp=rs-&gt;max_sum_lp;</span><br><span class="line">                max_sum_rp=rs-&gt;max_sum_rp;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">if</span>(max_sum&lt;ls-&gt;max_hz_sum+rs-&gt;max_qz_sum)&#123;</span><br><span class="line">                max_sum=ls-&gt;max_hz_sum+rs-&gt;max_qz_sum;</span><br><span class="line">                max_sum_lp=ls-&gt;max_hz_sum_lp;</span><br><span class="line">                max_sum_rp=rs-&gt;max_qz_sum_rp;</span><br><span class="line">            &#125;<span class="keyword">else</span> <span class="keyword">if</span>(max_sum==ls-&gt;max_hz_sum+rs-&gt;max_qz_sum)&#123;</span><br><span class="line">                <span class="keyword">if</span>(max_sum_lp&gt;ls-&gt;max_hz_sum_lp)&#123;</span><br><span class="line">                    max_sum=ls-&gt;max_hz_sum+rs-&gt;max_qz_sum;</span><br><span class="line">                    max_sum_lp=ls-&gt;max_hz_sum_lp;</span><br><span class="line">                    max_sum_rp=rs-&gt;max_qz_sum_rp;</span><br><span class="line">                &#125;<span class="keyword">else</span> <span class="keyword">if</span>(max_sum_lp==ls-&gt;max_hz_sum_lp)&#123;</span><br><span class="line">                    <span class="keyword">if</span>(max_sum_rp&gt;rs-&gt;max_qz_sum_rp)&#123;</span><br><span class="line">                        max_sum=ls-&gt;max_hz_sum+rs-&gt;max_qz_sum;</span><br><span class="line">                        max_sum_lp=ls-&gt;max_hz_sum_lp;</span><br><span class="line">                        max_sum_rp=rs-&gt;max_qz_sum_rp;</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;<span class="comment">//如您所见，由于愚蠢的“按字典序输出”存在，代码莫名其妙地增加了许多</span></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function">answ <span class="title">query_qz</span><span class="params">(<span class="type">int</span> r)</span></span>&#123;<span class="comment">//查询最大前缀和</span></span><br><span class="line">        <span class="keyword">if</span>(r&gt;=rp)&#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="built_in">answ</span>(<span class="number">0</span>,max_qz_sum_rp,max_qz_sum);</span><br><span class="line">        &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">            answ res=ls-&gt;<span class="built_in">query_qz</span>(r);</span><br><span class="line">            <span class="keyword">if</span>(r&gt;=rs-&gt;lp)&#123;</span><br><span class="line">                answ R=rs-&gt;<span class="built_in">query_qz</span>(r);</span><br><span class="line">                <span class="keyword">if</span>(res.k&lt;R.k+ls-&gt;sum)&#123;</span><br><span class="line">                    res=<span class="built_in">answ</span>(<span class="number">0</span>,R.j,R.k+ls-&gt;sum);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> res;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function">answ <span class="title">query_hz</span><span class="params">(<span class="type">int</span> l)</span></span>&#123;<span class="comment">//查询最大后缀和</span></span><br><span class="line">        <span class="keyword">if</span>(l&lt;=lp)&#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="built_in">answ</span>(max_hz_sum_lp,<span class="number">0</span>,max_hz_sum);</span><br><span class="line">        &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">            answ res=rs-&gt;<span class="built_in">query_hz</span>(l);</span><br><span class="line">            <span class="keyword">if</span>(l&lt;=ls-&gt;rp)&#123;</span><br><span class="line">                answ L=ls-&gt;<span class="built_in">query_hz</span>(l);</span><br><span class="line">                <span class="keyword">if</span>(res.k&lt;L.k+rs-&gt;sum)&#123;</span><br><span class="line">                    res=<span class="built_in">answ</span>(L.i,<span class="number">0</span>,L.k+rs-&gt;sum);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> res;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function">answ <span class="title">query</span><span class="params">(<span class="type">int</span> l,<span class="type">int</span> r)</span></span>&#123;<span class="comment">//查询最大字段和</span></span><br><span class="line">        <span class="keyword">if</span>(l&lt;=lp&amp;&amp;rp&lt;=r)&#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="built_in">answ</span>(max_sum_lp,max_sum_rp,max_sum);</span><br><span class="line">        &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">            answ <span class="built_in">res</span>(<span class="number">0</span>,<span class="number">0</span>,-INF),L,R;</span><br><span class="line">            <span class="keyword">if</span>(l&lt;=ls-&gt;rp)&#123;</span><br><span class="line">                L=ls-&gt;<span class="built_in">query</span>(l,r);</span><br><span class="line">                <span class="keyword">if</span>(L.k&gt;res.k)&#123;</span><br><span class="line">                    res=L;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">if</span>(r&gt;=rs-&gt;lp)&#123;</span><br><span class="line">                R=rs-&gt;<span class="built_in">query</span>(l,r);</span><br><span class="line">                <span class="keyword">if</span>(R.k&gt;res.k)&#123;</span><br><span class="line">                    res=R;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">if</span>(l&lt;=ls-&gt;rp&amp;&amp;r&gt;=rs-&gt;lp)&#123;</span><br><span class="line">                L=ls-&gt;<span class="built_in">query_hz</span>(l);</span><br><span class="line">                R=rs-&gt;<span class="built_in">query_qz</span>(r);</span><br><span class="line">                <span class="keyword">if</span>(L.k+R.k&gt;res.k)&#123;</span><br><span class="line">                    res=<span class="built_in">answ</span>(L.i,R.j,L.k+R.k);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> res;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;;</span><br><span class="line"><span class="type">int</span> n,m,a[MAXN+<span class="number">5</span>],sum[MAXN+<span class="number">5</span>];</span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span>&#123;</span><br><span class="line">    ios::<span class="built_in">sync_with_stdio</span>(<span class="literal">false</span>);</span><br><span class="line">    cin&gt;&gt;n&gt;&gt;m;</span><br><span class="line">    <span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">1</span>;i&lt;=n;i++)&#123;</span><br><span class="line">        cin&gt;&gt;a[i];</span><br><span class="line">        sum[i]=sum[i<span class="number">-1</span>]+a[i];</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function">segment_tree <span class="title">data</span><span class="params">(a,<span class="number">1</span>,n)</span></span>;</span><br><span class="line">    <span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">1</span>;i&lt;=m;i++)&#123;</span><br><span class="line">        <span class="type">int</span> l,r;</span><br><span class="line">        cin&gt;&gt;l&gt;&gt;r;</span><br><span class="line">        <span class="keyword">if</span>(r-l+<span class="number">1</span>&gt;<span class="number">33</span>)&#123;<span class="comment">//在数据量较小时使用暴力可以提高效率</span></span><br><span class="line">            answ ans=data.<span class="built_in">query</span>(l,r);</span><br><span class="line">            cout&lt;&lt;ans.i&lt;&lt;<span class="string">&quot; &quot;</span>&lt;&lt;ans.j&lt;&lt;<span class="string">&quot; &quot;</span>&lt;&lt;ans.k&lt;&lt;endl;</span><br><span class="line">        &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">            <span class="type">int</span> ansl=<span class="number">0</span>,ansr=<span class="number">0</span>,ans=-INF;</span><br><span class="line">            <span class="keyword">for</span>(<span class="type">int</span> j=l;j&lt;=r;j++)&#123;</span><br><span class="line">                <span class="keyword">for</span>(<span class="type">int</span> k=j;k&lt;=r;k++)&#123;</span><br><span class="line">                    <span class="keyword">if</span>(ans&lt;sum[k]-sum[j<span class="number">-1</span>])&#123;</span><br><span class="line">                        ansl=j;</span><br><span class="line">                        ansr=k;</span><br><span class="line">                        ans=sum[k]-sum[j<span class="number">-1</span>];</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            cout&lt;&lt;ansl&lt;&lt;<span class="string">&quot; &quot;</span>&lt;&lt;ansr&lt;&lt;<span class="string">&quot; &quot;</span>&lt;&lt;ans&lt;&lt;endl;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h6 id="4-点一个赞罢QwQ"><a href="#4-点一个赞罢QwQ" class="headerlink" title="4.点一个赞罢QwQ"></a>4.<del><em>点一个赞罢QwQ</em></del></h6>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://example.com/2021/07/29/%E5%B1%B1%E6%B5%B7%E7%BB%8F%20%E9%A2%98%E8%A7%A3/" data-id="clk9o8ln6000b8wi5ggry6srh" data-title="山海经 题解" class="article-share-link"><span class="fa fa-share">Share</span></a>
      
      
      
    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2021/07/30/UVA1619%20%E6%84%9F%E8%A7%89%E4%B8%8D%E9%94%99%20Feel%20Good%EF%BC%88%E8%89%AF%E5%A5%BD%E7%9A%84%E6%84%9F%E8%A7%89%EF%BC%89%20%E9%A2%98%E8%A7%A3/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          UVA1619 感觉不错 Feel Good（良好的感觉） 题解
        
      </div>
    </a>
  
  
    <a href="/2021/06/06/KMP%E7%AE%97%E6%B3%95%E8%AF%A6%E8%A7%A3/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">KMP算法详解</div>
    </a>
  
</nav>

  
</article>


</section>
        
          <aside id="sidebar">
  
    

  
    

  
    
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2023/07/">July 2023</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2022/10/">October 2022</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2022/05/">May 2022</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2022/02/">February 2022</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2022/01/">January 2022</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/08/">August 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/07/">July 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/06/">June 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/08/">August 2020</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2023/07/17/%E5%86%B3%E7%AD%96%E5%8D%95%E8%B0%83%E6%80%A7%E4%BC%98%E5%8C%96DP%20%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0%20AND%20P4767%20%E3%80%8CIOI2000%E3%80%8D%20%E9%82%AE%E5%B1%80%20%E9%A2%98%E8%A7%A3/">决策单调性优化DP 学习笔记 AND P4767 「IOI2000」 邮局 题解</a>
          </li>
        
          <li>
            <a href="/2022/10/30/CSP-S%202022%20%E6%B8%B8%E8%AE%B0/">CSP-S 2022 游记</a>
          </li>
        
          <li>
            <a href="/2022/05/29/%E6%96%9C%E7%8E%87%E4%BC%98%E5%8C%96%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92%20%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/">斜率优化动态规划 学习笔记</a>
          </li>
        
          <li>
            <a href="/2022/05/22/PKUSC%E4%B8%80%E5%8F%A5%E8%AF%9D%E6%B8%B8%E8%AE%B0/">PKUSC一句话游记</a>
          </li>
        
          <li>
            <a href="/2022/05/18/%E7%9C%81%E9%80%89%E6%B8%B8%E8%AE%B0%EF%BC%9F%E7%9C%81%E9%80%89%E6%B8%B8%E5%AF%84%EF%BC%81/">省选游记？省选游寄！</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      
      &copy; 2023 John Doe<br>
      Powered by <a href="https://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>

    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    


<script src="/js/jquery-3.6.4.min.js"></script>



  
<script src="/fancybox/jquery.fancybox.min.js"></script>




<script src="/js/script.js"></script>





  </div>
</body>
</html>